<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
    wrapClassName="ant-modal-cust-warp"
    style="top: 5%; height: 85%; overflow-y: hidden"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" v-bind="layout" :model="model">
        <a-form-model-item label="用户姓名" required prop="name">
          <a-input v-model="model.name" placeholder="请输入用户姓名" allow-clear />
        </a-form-model-item>

        <a-form-model-item label="预约活动" required prop="actId">
           <a-select
            v-model="model.actId"
            show-search
            :show-arrow="false"
            label-in-value
            placeholder="请输入需要预约的活动"
            style="width: 100%"
            :filter-option="false"
            :not-found-content="fetching ? undefined : null"
            :options="userOptions"
            @search="userChange"
          >
            <template v-if="fetching" #notFoundContent>
              <a-spin size="small" />
            </template>
          </a-select>
        </a-form-model-item>

        <a-form-model-item label="手机号" required prop="phone">
          <a-input v-model="model.phone"/>
        </a-form-model-item>

        <a-form-model-item label="身份证号" required prop="idCard">
          <a-input v-model="model.idCard"/>
        </a-form-model-item>

        <a-form-model-item label="紧急联系人" required prop="contacts">
          <a-input v-model="model.contacts"/>
        </a-form-model-item>

        <a-form-model-item label="血型" prop="blood">
          <a-input v-model="model.blood"/>
        </a-form-model-item>

        <a-form-model-item label="预约日期" required prop="appointTime">
          <a-input v-model="model.appointTime"/>
        </a-form-model-item>

        <a-form-model-item label="是否参保" required prop="insurance">
          <a-input v-model="model.insurance"/>
        </a-form-model-item>

        <a-form-model-item label="订单状态" required prop="status">
          <a-input v-model="model.status"/>
        </a-form-model-item>

        <a-form-model-item label="支付金额" prop="price">
          <a-input v-model="model.price"/>
        </a-form-model-item>


      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { getlikeuser} from '@/api/api'
export default {
  name: 'InsuranceModel',
  data() {
    return {
      title: '操作',
      visible: false,
      disableSubmit: false,
      fetching: false,
      userOptions:[],
      model: {},
      layout: {
        labelCol: { span: 3 },
        wrapperCol: { span: 14 },
      },
      confirmLoading: false,
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add() {
      this.visible = true
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, this.defaultModel, record)
      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    userChange(e){
      console.log('eee',e);
      this.fetching=true;
      const params = { keyword: e }
      this.userOptions=[];
      // getlikeuser(params).then(res=>{
      //    if (res.code === 20000 && res.data.length > 0) {
      //   for(var i=0;i<res.data.length;i++){
      //         const record = { label: res.data[i].realName, value: i}
      //         this.userOptions.push(record);
      //         this.fetching=false;
      //     }
      //     }
      // })
      return '1';
    },
    handleOk() {
      const that = this
      const params = that.model;
      let obj
      // if (!that.model.id) {
      //   obj = addInsurance(params)
      // } else {
      //   obj = editInsurance(params)
      // }
      // obj.then((res) => {
      //   if (res.code === 20000) {
      //     that.$message.success('添加成功！')
      //     that.close()
      //     that.$emit('ok')
      //   } else {
      //     that.$message.warning('添加失败！')
      //     that.close()
      //   }
      // })
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>

<style scoped>
</style>